home *** CD-ROM | disk | FTP | other *** search
/ 100 Plus Great Games 2 / 100PLUSV2.BIN / games / SphereShift.dxr / direction buttons_7_d buttons.ls < prev    next >
Encoding:
Text File  |  2002-01-25  |  19.1 KB  |  523 lines

  1. property button, buttonImage, spriteNum, inOperation, RowNum, ColNum
  2. global grid, CLRS, pScore, pScoreBox, points, gameOver, ScoreTotal, pScoreBoxTotal, victory, currentStage
  3.  
  4. on beginSprite me
  5.   inOperation = 0
  6.   button = new(script("direction buttons"), spriteNum)
  7.   buttonImage = sprite(spriteNum)
  8.   RowNum = GetGridRow()
  9.   ColNum = GetGridCol()
  10.   grid[RowNum][ColNum][1] = button
  11. end
  12.  
  13. on mouseDown me
  14.   if (buttonImage.member.name = "left") or (buttonImage.member.name = "right") then
  15.     puppetSound(4, member("moveleft-right"))
  16.   else
  17.     if (buttonImage.member.name = "down") or (buttonImage.member.name = "up") then
  18.       puppetSound(4, member("moveup-down"))
  19.     else
  20.       puppetSound(4, member("moveup-down"))
  21.       puppetSound(5, member("moveleft-right"))
  22.     end if
  23.   end if
  24.   if not inOperation then
  25.     if ilk(button, #object) then
  26.       inOperation = 1
  27.       sprite(spriteNum).member = member(sprite(spriteNum).member.name & "2", "direction buttons")
  28.       moveGamePieces(button.getDirection())
  29.       myname = sprite(spriteNum).member.name
  30.       sprite(spriteNum).member = member(chars(myname, 1, myname.char.count - 1), "direction buttons")
  31.       inOperation = 0
  32.       if (CLRS[1] = 0) and (CLRS[2] = 0) and (CLRS[3] = 0) and (CLRS = [4] = 0) and (CLRS[5] = 0) and (CLRS[6] = 0) then
  33.         gameOver = timeout("game won").new(450, #nextStage, me)
  34.       else
  35.         repeat with i = 1 to CLRS.count
  36.           if CLRS[i] = 1 then
  37.             gameOver = timeout("game over").new(450, #endGame, me)
  38.           end if
  39.         end repeat
  40.       end if
  41.     end if
  42.   end if
  43. end
  44.  
  45. on moveGamePieces dirOfMove
  46.   if ilk(dirOfMove, #symbol) then
  47.     if dirOfMove = #left then
  48.       posList = []
  49.       repeat with pse = grid[RowNum].findPos([button]) down to 1
  50.         if ilk(grid[RowNum][pse][1], #object) then
  51.           if grid[RowNum][pse][1].script = script("direction buttons") then
  52.             if grid[RowNum][pse][1].spriteNum <> spriteNum then
  53.               exit repeat
  54.             end if
  55.           end if
  56.         else
  57.           if grid[RowNum][pse][1] = #block then
  58.             exit repeat
  59.           end if
  60.         end if
  61.         posList.add(pse)
  62.       end repeat
  63.       posList.sort()
  64.       repeat with piece in posList
  65.         if ilk(grid[RowNum][piece][1], #object) then
  66.           if grid[RowNum][piece][1].script = script("game pieces") then
  67.             if piece > 1 then
  68.               if grid[RowNum][piece - 1][1] = #empty then
  69.                 grid[RowNum][piece][1].MoveThis(dirOfMove)
  70.                 grid[RowNum][piece - 1][1] = grid[RowNum][piece][1]
  71.                 grid[RowNum][piece][1] = #empty
  72.               end if
  73.             end if
  74.           end if
  75.         end if
  76.       end repeat
  77.       posList.deleteAll()
  78.       upYours()
  79.     else
  80.       if dirOfMove = #right then
  81.         posList = []
  82.         repeat with pse = grid[RowNum].findPos([button]) to grid[RowNum].count
  83.           if ilk(grid[RowNum][pse][1], #object) then
  84.             if grid[RowNum][pse][1].script = script("direction buttons") then
  85.               if grid[RowNum][pse][1].spriteNum <> spriteNum then
  86.                 exit repeat
  87.               end if
  88.             end if
  89.           else
  90.             if grid[RowNum][pse][1] = #block then
  91.               exit repeat
  92.             end if
  93.           end if
  94.           posList.add(pse)
  95.         end repeat
  96.         posList.sort()
  97.         repeat with piece = posList.count down to 1
  98.           if ilk(grid[RowNum][posList[piece]][1], #object) then
  99.             if grid[RowNum][posList[piece]][1].script = script("game pieces") then
  100.               if piece > 1 then
  101.                 if grid[RowNum][posList[piece] + 1][1] = #empty then
  102.                   grid[RowNum][posList[piece]][1].MoveThis(dirOfMove)
  103.                   grid[RowNum][posList[piece] + 1][1] = grid[RowNum][posList[piece]][1]
  104.                   grid[RowNum][posList[piece]][1] = #empty
  105.                 end if
  106.               end if
  107.             end if
  108.           end if
  109.         end repeat
  110.         posList.deleteAll()
  111.         upYours()
  112.       else
  113.         if dirOfMove = #up then
  114.           posList = []
  115.           repeat with pse = RowNum down to 1
  116.             if ilk(grid[pse][ColNum][1], #object) then
  117.               if grid[pse][ColNum][1].script = script("direction buttons") then
  118.                 if grid[pse][ColNum][1].spriteNum <> spriteNum then
  119.                   exit repeat
  120.                 end if
  121.               end if
  122.             else
  123.               if grid[pse][ColNum][1] = #block then
  124.                 exit repeat
  125.               end if
  126.             end if
  127.             posList.add(pse)
  128.           end repeat
  129.           posList.sort()
  130.           repeat with piece = 1 to posList.count
  131.             if ilk(grid[posList[piece]][ColNum][1], #object) then
  132.               if grid[posList[piece]][ColNum][1].script = script("game pieces") then
  133.                 if piece > 1 then
  134.                   if grid[posList[piece] - 1][ColNum][1] = #empty then
  135.                     grid[posList[piece]][ColNum][1].MoveThis(dirOfMove)
  136.                     grid[posList[piece] - 1][ColNum][1] = grid[posList[piece]][ColNum][1]
  137.                     grid[posList[piece]][ColNum][1] = #empty
  138.                   end if
  139.                 end if
  140.               end if
  141.             end if
  142.           end repeat
  143.           upYours()
  144.         else
  145.           if dirOfMove = #down then
  146.             posList = []
  147.             repeat with pse = RowNum to grid.count
  148.               if ilk(grid[pse][ColNum][1], #object) then
  149.                 if grid[pse][ColNum][1].script = script("direction buttons") then
  150.                   if grid[pse][ColNum][1].spriteNum <> spriteNum then
  151.                     exit repeat
  152.                   end if
  153.                 end if
  154.               else
  155.                 if grid[pse][ColNum][1] = #block then
  156.                   exit repeat
  157.                 end if
  158.               end if
  159.               posList.add(pse)
  160.             end repeat
  161.             posList.sort()
  162.             repeat with piece = posList.count down to 1
  163.               if ilk(grid[posList[piece]][ColNum][1], #object) then
  164.                 if grid[posList[piece]][ColNum][1].script = script("game pieces") then
  165.                   if piece < grid.count then
  166.                     if grid[posList[piece] + 1][ColNum][1] = #empty then
  167.                       grid[posList[piece]][ColNum][1].MoveThis(dirOfMove)
  168.                       grid[posList[piece] + 1][ColNum][1] = grid[posList[piece]][ColNum][1]
  169.                       grid[posList[piece]][ColNum][1] = #empty
  170.                     end if
  171.                   end if
  172.                 end if
  173.               end if
  174.             end repeat
  175.             upYours()
  176.           else
  177.             if dirOfMove = #multi then
  178.               repeat with directiontoGo in [#left, #up, #right, #down]
  179.                 if directiontoGo = #left then
  180.                   posList = []
  181.                   repeat with pse = grid[RowNum].findPos([button]) down to 1
  182.                     if ilk(grid[RowNum][pse][1], #object) then
  183.                       if grid[RowNum][pse][1].script = script("direction buttons") then
  184.                         if grid[RowNum][pse][1].spriteNum <> spriteNum then
  185.                           exit repeat
  186.                         end if
  187.                       end if
  188.                     end if
  189.                     posList.add(pse)
  190.                   end repeat
  191.                   posList.sort()
  192.                   repeat with piece in posList
  193.                     if ilk(grid[RowNum][piece][1], #object) then
  194.                       if grid[RowNum][piece][1].script = script("game pieces") then
  195.                         if piece > 1 then
  196.                           if grid[RowNum][piece - 1][1] = #empty then
  197.                             grid[RowNum][piece][1].MoveThis(directiontoGo)
  198.                             grid[RowNum][piece - 1][1] = grid[RowNum][piece][1]
  199.                             grid[RowNum][piece][1] = #empty
  200.                           end if
  201.                         end if
  202.                       end if
  203.                     end if
  204.                   end repeat
  205.                   posList.deleteAll()
  206.                   next repeat
  207.                 end if
  208.                 if directiontoGo = #up then
  209.                   posList = []
  210.                   repeat with pse = RowNum down to 1
  211.                     if ilk(grid[pse][ColNum][1], #object) then
  212.                       if grid[pse][ColNum][1].script = script("direction buttons") then
  213.                         if grid[pse][ColNum][1].spriteNum <> spriteNum then
  214.                           exit repeat
  215.                         end if
  216.                       end if
  217.                     end if
  218.                     posList.add(pse)
  219.                   end repeat
  220.                   posList.sort()
  221.                   repeat with piece = 1 to posList.count
  222.                     if ilk(grid[posList[piece]][ColNum][1], #object) then
  223.                       if grid[posList[piece]][ColNum][1].script = script("game pieces") then
  224.                         if piece > 1 then
  225.                           if grid[posList[piece] - 1][ColNum][1] = #empty then
  226.                             grid[posList[piece]][ColNum][1].MoveThis(directiontoGo)
  227.                             grid[posList[piece] - 1][ColNum][1] = grid[posList[piece]][ColNum][1]
  228.                             grid[posList[piece]][ColNum][1] = #empty
  229.                           end if
  230.                         end if
  231.                       end if
  232.                     end if
  233.                   end repeat
  234.                   next repeat
  235.                 end if
  236.                 if directiontoGo = #right then
  237.                   posList = []
  238.                   repeat with pse = grid[RowNum].findPos([button]) to grid[RowNum].count
  239.                     if ilk(grid[RowNum][pse][1], #object) then
  240.                       if grid[RowNum][pse][1].script = script("direction buttons") then
  241.                         if grid[RowNum][pse][1].spriteNum <> spriteNum then
  242.                           exit repeat
  243.                         end if
  244.                       end if
  245.                     end if
  246.                     posList.add(pse)
  247.                   end repeat
  248.                   posList.sort()
  249.                   repeat with piece = posList.count down to 1
  250.                     if ilk(grid[RowNum][posList[piece]][1], #object) then
  251.                       if grid[RowNum][posList[piece]][1].script = script("game pieces") then
  252.                         if piece > 1 then
  253.                           if grid[RowNum][posList[piece] + 1][1] = #empty then
  254.                             grid[RowNum][posList[piece]][1].MoveThis(directiontoGo)
  255.                             grid[RowNum][posList[piece] + 1][1] = grid[RowNum][posList[piece]][1]
  256.                             grid[RowNum][posList[piece]][1] = #empty
  257.                           end if
  258.                         end if
  259.                       end if
  260.                     end if
  261.                   end repeat
  262.                   posList.deleteAll()
  263.                   next repeat
  264.                 end if
  265.                 if directiontoGo = #down then
  266.                   posList = []
  267.                   repeat with pse = RowNum to grid.count
  268.                     if ilk(grid[pse][ColNum][1], #object) then
  269.                       if grid[pse][ColNum][1].script = script("direction buttons") then
  270.                         if grid[pse][ColNum][1].spriteNum <> spriteNum then
  271.                           exit repeat
  272.                         end if
  273.                       end if
  274.                     end if
  275.                     posList.add(pse)
  276.                   end repeat
  277.                   posList.sort()
  278.                   repeat with piece = posList.count down to 1
  279.                     if ilk(grid[posList[piece]][ColNum][1], #object) then
  280.                       if grid[posList[piece]][ColNum][1].script = script("game pieces") then
  281.                         if piece < grid.count then
  282.                           if grid[posList[piece] + 1][ColNum][1] = #empty then
  283.                             grid[posList[piece]][ColNum][1].MoveThis(directiontoGo)
  284.                             grid[posList[piece] + 1][ColNum][1] = grid[posList[piece]][ColNum][1]
  285.                             grid[posList[piece]][ColNum][1] = #empty
  286.                           end if
  287.                         end if
  288.                       end if
  289.                     end if
  290.                   end repeat
  291.                 end if
  292.               end repeat
  293.               upYours()
  294.             end if
  295.           end if
  296.         end if
  297.       end if
  298.     end if
  299.   end if
  300.   testToMatchHor()
  301.   testToMatchVer()
  302. end
  303.  
  304. on testToMatchHor me
  305.   repeat with row = 1 to grid.count
  306.     repeat with col = 1 to grid[row].count
  307.       if ilk(grid[row][col][1], #object) then
  308.         if grid[row][col][1].script = script("game pieces") then
  309.           if col <> grid[row].count then
  310.             colorMLIST = []
  311.             repeat with i = col + 1 to grid[row].count
  312.               if ilk(grid[row][i][1], #object) then
  313.                 if grid[row][i][1].script = script("game pieces") then
  314.                   if grid[row][col][1].myColor = grid[row][i][1].myColor then
  315.                     colorMLIST.add(grid[row][i][1])
  316.                     xtc = i
  317.                   else
  318.                     exit repeat
  319.                   end if
  320.                 else
  321.                   exit repeat
  322.                 end if
  323.                 next repeat
  324.               end if
  325.               exit repeat
  326.             end repeat
  327.             if colorMLIST.count > 0 then
  328.               tempClr = grid[row][col][1].myColor
  329.               repeat with zs = col to xtc
  330.                 CLRS[symbol(tempClr)] = CLRS[symbol(tempClr)] - 1
  331.                 grid[row][zs][1].getRid()
  332.                 grid[row][zs][1] = #empty
  333.                 pScore = value(pScore) + points
  334.                 ScoreTotal = ScoreTotal + points
  335.                 pScoreBoxTotal.text = string(ScoreTotal)
  336.                 pScoreBox.text = string(pScore)
  337.               end repeat
  338.               puppetSound(2, member("dissapear"))
  339.               colorMLIST.deleteAll()
  340.             end if
  341.           end if
  342.         end if
  343.       end if
  344.     end repeat
  345.   end repeat
  346. end
  347.  
  348. on testToMatchVer me
  349.   repeat with row = 1 to grid.count
  350.     repeat with col = 1 to grid[row].count
  351.       if ilk(grid[row][col][1], #object) then
  352.         if grid[row][col][1].script = script("game pieces") then
  353.           if col <> grid[row].count then
  354.             colorMLIST = []
  355.             repeat with i = row + 1 to grid.count
  356.               if ilk(grid[i][col][1], #object) then
  357.                 if grid[i][col][1].script = script("game pieces") then
  358.                   if grid[row][col][1].myColor = grid[i][col][1].myColor then
  359.                     colorMLIST.add(grid[i][col][1])
  360.                     xtc = i
  361.                   else
  362.                     exit repeat
  363.                   end if
  364.                 else
  365.                   exit repeat
  366.                 end if
  367.                 next repeat
  368.               end if
  369.               exit repeat
  370.             end repeat
  371.             if colorMLIST.count > 0 then
  372.               tempClr = grid[row][col][1].myColor
  373.               repeat with zs = row to xtc
  374.                 CLRS[symbol(tempClr)] = CLRS[symbol(tempClr)] - 1
  375.                 grid[zs][col][1].getRid()
  376.                 grid[zs][col][1] = #empty
  377.                 pScore = value(pScore) + points
  378.                 pScoreBox.text = string(pScore)
  379.                 ScoreTotal = ScoreTotal + points
  380.                 pScoreBoxTotal.text = string(ScoreTotal)
  381.               end repeat
  382.               puppetSound(2, member("dissapear"))
  383.               colorMLIST.deleteAll()
  384.             end if
  385.           end if
  386.         end if
  387.       end if
  388.     end repeat
  389.   end repeat
  390. end
  391.  
  392. on endGame me
  393.   gameOver.forget()
  394.   victory = #no
  395.   go("end")
  396. end
  397.  
  398. on nextStage me
  399.   gameOver.forget()
  400.   cC = currentStage.char.count
  401.   if value(currentStage.char[cC]) < 5 then
  402.     go(string(value(currentStage.char[cC]) + 1))
  403.   else
  404.     if value(currentStage.char[cC]) = 5 then
  405.       victory = #yes
  406.       go("end")
  407.     end if
  408.   end if
  409. end
  410.  
  411. on upYours me
  412.   if (the actorList).count = 0 then
  413.     inOperation = 0
  414.   else
  415.     if (the actorList).count > 0 then
  416.       repeat while (the actorList).count > 0
  417.         updateStage()
  418.       end repeat
  419.       inOperation = 0
  420.     end if
  421.   end if
  422. end
  423.  
  424. on GetGridRow me
  425.   if (buttonImage.locV >= 26) and (buttonImage.locV <= 60) then
  426.     return 1
  427.   else
  428.     if (buttonImage.locV >= 60) and (buttonImage.locV <= 95) then
  429.       return 2
  430.     else
  431.       if (buttonImage.locV >= 95) and (buttonImage.locV <= 130) then
  432.         return 3
  433.       else
  434.         if (buttonImage.locV >= 130) and (buttonImage.locV <= 165) then
  435.           return 4
  436.         else
  437.           if (buttonImage.locV >= 165) and (buttonImage.locV <= 200) then
  438.             return 5
  439.           else
  440.             if (buttonImage.locV >= 200) and (buttonImage.locV <= 235) then
  441.               return 6
  442.             else
  443.               if (buttonImage.locV >= 235) and (buttonImage.locV <= 270) then
  444.                 return 7
  445.               else
  446.                 if (buttonImage.locV >= 270) and (buttonImage.locV <= 305) then
  447.                   return 8
  448.                 else
  449.                   if (buttonImage.locV >= 305) and (buttonImage.locV <= 340) then
  450.                     return 9
  451.                   else
  452.                     if (buttonImage.locV >= 340) and (buttonImage.locV <= 375) then
  453.                       return 10
  454.                     else
  455.                       if (buttonImage.locV >= 375) and (buttonImage.locV <= 410) then
  456.                         return 11
  457.                       end if
  458.                     end if
  459.                   end if
  460.                 end if
  461.               end if
  462.             end if
  463.           end if
  464.         end if
  465.       end if
  466.     end if
  467.   end if
  468. end
  469.  
  470. on GetGridCol me
  471.   if (buttonImage.locH >= 27) and (buttonImage.locH <= 61) then
  472.     return 1
  473.   else
  474.     if (buttonImage.locH >= 61) and (buttonImage.locH <= 96) then
  475.       return 2
  476.     else
  477.       if (buttonImage.locH >= 96) and (buttonImage.locH <= 131) then
  478.         return 3
  479.       else
  480.         if (buttonImage.locH >= 131) and (buttonImage.locH <= 166) then
  481.           return 4
  482.         else
  483.           if (buttonImage.locH >= 166) and (buttonImage.locH <= 201) then
  484.             return 5
  485.           else
  486.             if (buttonImage.locH >= 201) and (buttonImage.locH <= 236) then
  487.               return 6
  488.             else
  489.               if (buttonImage.locH >= 236) and (buttonImage.locH <= 271) then
  490.                 return 7
  491.               else
  492.                 if (buttonImage.locH >= 271) and (buttonImage.locH <= 306) then
  493.                   return 8
  494.                 else
  495.                   if (buttonImage.locH >= 306) and (buttonImage.locH <= 341) then
  496.                     return 9
  497.                   else
  498.                     if (buttonImage.locH >= 341) and (buttonImage.locH <= 376) then
  499.                       return 10
  500.                     else
  501.                       if (buttonImage.locH >= 376) and (buttonImage.locH <= 411) then
  502.                         return 11
  503.                       else
  504.                         if (buttonImage.locH >= 411) and (buttonImage.locH <= 447) then
  505.                           return 12
  506.                         else
  507.                           if (buttonImage.locH >= 447) and (buttonImage.locH <= 481) then
  508.                             return 13
  509.                           end if
  510.                         end if
  511.                       end if
  512.                     end if
  513.                   end if
  514.                 end if
  515.               end if
  516.             end if
  517.           end if
  518.         end if
  519.       end if
  520.     end if
  521.   end if
  522. end
  523.